<template>
    <div class="ohip14-survey">
        <div class="header">
            <h1>{{ surveyConfig.title }}</h1>
            <p class="subtitle">{{ surveyConfig.subtitle }}</p>
            <div class="header-actions">
                <button @click="goToHome" class="home-btn">
                    <span class="home-icon">🏠</span> {{ surveyConfig.ui.buttons.home }}
                </button>
                <button @click="showSettings = true" class="settings-btn">
                    <span class="settings-icon">⚙️</span> {{ surveyConfig.ui.buttons.settings }}
                </button>
            </div>
        </div>

        <!-- 设置页面 -->
        <div class="settings-modal" v-if="showSettings">
            <div class="settings-content">
                <div class="settings-header">
                    <h2>{{ surveyConfig.settings.title }}</h2>
                    <button @click="closeSettings" class="close-btn">×</button>
                </div>

                <div class="settings-form">
                    <div class="form-group">
                        <label>问答编号：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.surveyId" placeholder="请输入问答编号（用于区分不同组的问卷）"
                            maxlength="20">
                        <p class="field-hint">编号用于区分不同组的问卷，建议使用如：OHIP001、ORAL_A等格式</p>
                    </div>
                    <div class="form-group">
                        <label>记录人姓名：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.name" placeholder="请输入记录人姓名">
                    </div>
                    <div class="form-group">
                        <label>记录人职务/身份：<span class="required">*</span></label>
                        <input type="text" v-model="recorderInfo.position" placeholder="请输入职务或身份（如：医生、护士、研究员等）">
                    </div>
                    <div class="form-group">
                        <label>所属机构：</label>
                        <input type="text" v-model="recorderInfo.institution" placeholder="请输入所属医院或机构名称">
                    </div>
                    <div class="form-group">
                        <label>联系方式：</label>
                        <input type="text" v-model="recorderInfo.contact" placeholder="请输入联系电话或邮箱">
                    </div>
                    <div class="form-group">
                        <label>默认备注：</label>
                        <textarea v-model="recorderInfo.defaultRemarks" placeholder="请输入默认备注信息（可选）" rows="3"></textarea>
                    </div>
                </div>

                <div class="settings-actions">
                    <button @click="saveRecorderInfo" class="save-settings-btn">保存设置</button>
                    <button @click="closeSettings" class="cancel-btn">取消</button>
                </div>
            </div>
        </div>

        <!-- 记录人信息显示 -->
        <div class="recorder-info-display" v-if="recorderInfo.name && !showSettings && !showResult && !showExport">
            <div class="recorder-card">
                <div class="recorder-main-info">
                    <h3>问答编号：{{ recorderInfo.surveyId }}</h3>
                    <p>记录人：{{ recorderInfo.name }} | {{ recorderInfo.position }}</p>
                    <p v-if="recorderInfo.institution">{{ recorderInfo.institution }}</p>
                </div>
                <div class="recorder-actions">
                    <button @click="showSettings = true" class="edit-recorder-btn">编辑</button>
                    <button @click="showExportDialog" class="export-btn">{{ surveyConfig.ui.buttons.export }}</button>
                </div>
            </div>
        </div>

        <!-- 导出数据模态框 -->
        <div class="export-modal" v-if="showExport">
            <div class="export-content">
                <div class="export-header">
                    <h2>{{ surveyConfig.export.title }}</h2>
                    <button @click="closeExport" class="close-btn">×</button>
                </div>

                <div class="export-form">
                    <div class="export-info">
                        <p><strong>当前问答编号：</strong>{{ recorderInfo.surveyId }}</p>
                        <p><strong>导出说明：</strong>将从服务器打包当前编号的所有OHIP-14问卷数据</p>
                    </div>

                    <div class="form-group">
                        <label>导出密码：<span class="required">*</span></label>
                        <input type="password" v-model="exportPassword" placeholder="请输入导出密码" @keyup.enter="exportData">
                        <p class="field-hint">请联系管理员获取导出密码</p>
                    </div>

                    <div class="export-options">
                        <div class="form-group">
                            <label>
                                <input type="checkbox" v-model="exportOptions.includeRawData">
                                包含原始评估数据
                            </label>
                        </div>
                        <div class="form-group">
                            <label>
                                <input type="checkbox" v-model="exportOptions.includeStatistics">
                                包含统计信息
                            </label>
                        </div>
                    </div>

                    <div class="export-actions">
                        <button @click="exportData" class="export-confirm-btn"
                            :disabled="isExporting || !exportPassword">
                            <span v-if="!isExporting">确认导出</span>
                            <span v-else>导出中...</span>
                        </button>
                        <button @click="closeExport" class="cancel-btn">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 表单 -->
        <div class="survey-form" v-if="!showResult && !showSettings && !showExport">
            <!-- 基本信息 -->
            <div class="section">
                <h2>{{ surveyConfig.sections.basicInfo.title }}</h2>
                <div class="form-grid">
                    <div v-for="field in surveyConfig.sections.basicInfo.fields" :key="field.name" class="form-group"
                        :class="{ 'full-width': field.type === 'textarea' }">
                        <label>
                            {{ field.label }}
                            <span v-if="field.required" class="required">*</span>
                        </label>

                        <!-- 文本输入 -->
                        <input v-if="field.type === 'text' || field.type === 'tel'" :type="field.type"
                            v-model="formData[field.name]" :placeholder="field.placeholder" class="form-input">

                        <!-- 数字输入 -->
                        <input v-else-if="field.type === 'number'" type="number" v-model.number="formData[field.name]"
                            :placeholder="field.placeholder" :min="field.min" :max="field.max" class="form-input">

                        <!-- 单选按钮 -->
                        <div v-else-if="field.type === 'radio'" class="radio-group">
                            <label v-for="option in field.options" :key="option.value" class="radio-option">
                                <input type="radio" :name="field.name" :value="option.value"
                                    v-model="formData[field.name]">
                                <span class="radio-label">{{ option.label }}</span>
                            </label>
                        </div>

                        <!-- 日期时间输入 -->
                        <input v-else-if="field.type === 'datetime-local'" type="datetime-local"
                            v-model="formData[field.name]" class="form-input">

                        <!-- 文本域 -->
                        <textarea v-else-if="field.type === 'textarea'" v-model="formData[field.name]"
                            :placeholder="field.placeholder" class="form-textarea" :rows="field.rows || 3"></textarea>
                    </div>
                </div>
            </div>

            <!-- 评估问题 -->
            <div class="section">
                <h2>{{ surveyConfig.sections.assessment.title }}</h2>
                <p class="section-description">{{ surveyConfig.instruction }}</p>

                <div v-for="group in surveyConfig.formGroups" :key="group.id" class="question-group">
                    <h3 v-if="group.title">{{ group.title }}</h3>
                    <p v-if="group.description" class="group-description">{{ group.description }}</p>

                    <div v-for="question in group.questions" :key="question.id" class="question-item">
                        <div class="question-header">
                            <label class="question-label">
                                {{ question.label }}
                                <span v-if="question.required" class="required">*</span>
                            </label>
                        </div>

                        <!-- 单选按钮 -->
                        <div v-if="question.type === 'radio'" class="radio-group">
                            <label v-for="option in question.options" :key="option.value" class="radio-option">
                                <input type="radio" :name="question.id" :value="option.value"
                                    v-model="formData[question.id]" @change="handleQuestionChange(question.id)">
                                <span class="radio-label">{{ option.label }}</span>
                            </label>
                        </div>
                    </div>
                </div>

                <!-- 提交按钮 -->
                <div class="form-navigation">
                    <button @click="calculateResult" class="nav-btn submit-btn" :disabled="!isFormValid">
                        {{ surveyConfig.ui.buttons.submit }}
                    </button>
                </div>
            </div>
        </div>

        <!-- 结果展示 -->
        <div class="result-section" v-if="showResult">
            <h2>OHIP-14评估结果</h2>
            <div class="result-card">
                <div class="result-summary">
                    <h3>{{ result.diagnosis }}</h3>
                    <p class="score">总分：{{ result.totalScore }}/{{ result.maxScore }}</p>
                </div>

                <div class="result-details" v-if="result.details">
                    <h4>各问题得分详情：</h4>
                    <div class="question-scores-grid">
                        <div v-for="question in result.details.questions" :key="question.id"
                            class="question-score-item">
                            <span class="question-id">{{ question.id }}</span>
                            <span class="question-label">{{ question.label }}</span>
                            <span class="question-score">得分：{{ question.score }}</span>
                        </div>
                    </div>
                </div>

                <div class="result-explanation">
                    <h4>评估说明：</h4>
                    <p>{{ result.explanation }}</p>
                </div>

                <div class="action-buttons">
                    <button @click="saveToBackendOnly" class="save-btn" :disabled="isSaving">
                        <span v-if="!isSaving">{{ surveyConfig.ui.buttons.save || '保存结果' }}</span>
                        <span v-else>保存中...</span>
                    </button>
                    <button @click="resetForm" class="reset-btn">{{ surveyConfig.ui.buttons.restart }}</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { ohip14Config } from '@/config/ohip14Config.js';
import { calculateOHIP14Assessment } from '@/config/ohip14Logic.js';

export default {
    name: 'OHIP14Survey',
    mounted() {
        // 自动设置当前时间
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0');
        const day = String(now.getDate()).padStart(2, '0');
        const hours = String(now.getHours()).padStart(2, '0');
        const minutes = String(now.getMinutes()).padStart(2, '0');
        this.formData.recordTime = `${year}-${month}-${day}T${hours}:${minutes}`;

        // 加载记录人信息
        this.loadRecorderInfo();

        // 初始化表单数据
        this.initializeForm();
    },
    data() {
        return {
            surveyConfig: ohip14Config,
            showResult: false,
            showSettings: false,
            showExport: false,
            isExporting: false,
            isSaving: false,
            exportPassword: '',
            // 记录人信息（设置）
            recorderInfo: {
                surveyId: '',
                name: '',
                position: '',
                institution: '',
                contact: '',
                defaultRemarks: ''
            },
            // 导出选项
            exportOptions: {
                includeRawData: true,
                includeStatistics: true
            },
            // 问卷表单数据
            formData: {},
            result: {
                totalScore: 0,
                maxScore: 56,
                diagnosis: '',
                explanation: '',
                details: {}
            }
        }
    },
    computed: {
        isFormValid() {
            // 检查基本信息
            if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
                return false;
            }
            // 个人信息字段已改为选填，不再进行必填验证

            // 检查所有14个问题是否已回答
            for (let i = 1; i <= 14; i++) {
                const questionId = `Q${String(i).padStart(2, '0')}`;
                if (this.formData[questionId] === undefined || this.formData[questionId] === null || this.formData[questionId] === '') {
                    return false;
                }
            }

            return true;
        }
    },
    methods: {
        // 导航方法
        goToHome() {
            this.$router.push('/');
        },

        // 初始化表单数据
        initializeForm() {
            // 保留已设置的recordTime值
            const existingRecordTime = this.formData.recordTime;

            this.formData = {
                recordTime: existingRecordTime || ''
            };

            // 初始化所有字段为空值
            this.surveyConfig.formGroups.forEach(group => {
                group.questions.forEach(question => {
                    if (!Object.prototype.hasOwnProperty.call(this.formData, question.id)) {
                        this.formData[question.id] = '';
                    }
                });
            });
        },

        // 设置相关方法
        saveRecorderInfo() {
            // 验证必填字段
            if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
                alert('请填写所有必填信息（问答编号、记录人姓名、职务/身份）！');
                return;
            }

            // 保存记录人信息到本地存储
            localStorage.setItem('ohip14RecorderInfo', JSON.stringify(this.recorderInfo));
            // 设置默认备注
            if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
                this.formData.remarks = this.recorderInfo.defaultRemarks;
            }
            this.showSettings = false;
            alert('记录人信息已保存！');
        },

        closeSettings() {
            this.showSettings = false;
        },

        loadRecorderInfo() {
            // 从本地存储加载记录人信息
            const saved = localStorage.getItem('ohip14RecorderInfo');
            if (saved) {
                this.recorderInfo = JSON.parse(saved);
                // 设置默认备注
                if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
                    this.formData.remarks = this.recorderInfo.defaultRemarks;
                }
            }
        },

        // 导出相关方法
        showExportDialog() {
            this.showExport = true;
            this.exportPassword = '';
        },

        closeExport() {
            this.showExport = false;
            this.exportPassword = '';
            this.isExporting = false;
        },

        async exportData() {
            this.isExporting = true;

            try {
                // 发送导出请求到服务器
                const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/export-ohip14-survey`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        surveyId: this.recorderInfo.surveyId,
                        password: this.exportPassword,
                        exportOptions: this.exportOptions
                    })
                });

                if (response.status === 401) {
                    alert('密码错误，请重新输入！');
                    return;
                }

                if (!response.ok) {
                    throw new Error('导出请求失败');
                }

                // 获取服务器返回的压缩包
                const blob = await response.blob();

                if (blob.size === 0) {
                    alert('当前问答编号下没有OHIP-14问卷数据！');
                    return;
                }

                // 下载服务器生成的压缩包
                const url = window.URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.href = url;
                link.download = `OHIP14问卷数据_${this.recorderInfo.surveyId}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.zip`;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                window.URL.revokeObjectURL(url);

                alert('数据导出成功！');
                this.closeExport();
            } catch (error) {
                console.error('导出失败:', error);
                alert('导出失败，请检查网络连接或联系管理员！');
            } finally {
                this.isExporting = false;
            }
        },

        // 表单处理方法
        // eslint-disable-next-line no-unused-vars
        handleQuestionChange(questionId) {
            // 当问题答案改变时，可以在这里添加额外逻辑
            // 当前OHIP-14问卷无需条件性问题处理，但保留方法以便将来扩展
        },

        calculateResult() {
            // 使用OHIP-14评估逻辑
            this.result = calculateOHIP14Assessment(this.formData);
            this.showResult = true;
        },

        async saveToBackendOnly() {
            this.isSaving = true;

            try {
                // 1. 保存问卷数据到后台
                await this.saveToBackend();

                // 2. 生成评估报告内容
                const timestamp = new Date().toLocaleString('zh-CN');
                const recordTime = this.formData.recordTime ?
                    new Date(this.formData.recordTime).toLocaleString('zh-CN') :
                    timestamp;

                const content = `口腔健康影响程度量表(OHIP-14)评估结果报告
问答编号：${this.recorderInfo.surveyId}
生成时间：${timestamp}

=== 记录人信息 ===
记录人姓名：${this.recorderInfo.name}
记录人职务/身份：${this.recorderInfo.position}
所属机构：${this.recorderInfo.institution}
联系方式：${this.recorderInfo.contact}
记录时间：${recordTime}
备注：${this.formData.remarks || '无'}

=== 被评估人基本信息 ===
姓名：${this.formData.patientName}
年龄：${this.formData.age}岁
性别：${this.formData.gender === 'male' ? '男性' : '女性'}
联系电话：${this.formData.phone || '未填写'}

=== 评估结果 ===
总分：${this.result.totalScore}/${this.result.maxScore}
诊断结果：${this.result.diagnosis}

=== 各问题得分详情 ===
${this.result.details.questions.map(q =>
                    `${q.id}. ${q.label}：${q.score}分`
                ).join('\n')}

=== 评估说明 ===
${this.result.explanation}

报告结束
`;

                // 3. 保存评估报告到@data/文件夹
                await this.saveFileToDataFolder(content);

                alert('✅ 数据已成功保存到后台！\n\n📁 问卷数据：survey_data/\n📄 评估报告：@data/');

            } catch (error) {
                console.error('保存到后台失败:', error);
                alert('❌ 保存失败，请检查网络连接或联系管理员！\n\n错误信息：' + error.message);
            } finally {
                this.isSaving = false;
            }
        },

        async saveToBackend() {
            // 构建符合OHIP14SurveyData模型的数据格式
            const surveyData = {
                surveyId: this.recorderInfo.surveyId,
                recordTime: new Date().toISOString(),
                recorderName: this.recorderInfo.name,
                recorderPosition: this.recorderInfo.position,
                recorderInstitution: this.recorderInfo.institution,
                recorderContact: this.recorderInfo.contact,
                patientName: this.formData.patientName || "未填写",
                age: this.formData.age || 0,
                gender: this.formData.gender,
                phone: this.formData.phone,
                remarks: this.formData.remarks,
                // 原始问卷字段
                Q01: this.formData.Q01,
                Q02: this.formData.Q02,
                Q03: this.formData.Q03,
                Q04: this.formData.Q04,
                Q05: this.formData.Q05,
                Q06: this.formData.Q06,
                Q07: this.formData.Q07,
                Q08: this.formData.Q08,
                Q09: this.formData.Q09,
                Q10: this.formData.Q10,
                Q11: this.formData.Q11,
                Q12: this.formData.Q12,
                Q13: this.formData.Q13,
                Q14: this.formData.Q14,
                // 计算结果
                totalScore: this.result.totalScore,
                maxScore: this.result.maxScore,
                diagnosis: this.result.diagnosis,
                createdAt: new Date().toISOString()
            };

            const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-ohip14-survey`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(surveyData)
            });

            if (!response.ok) {
                throw new Error('保存问卷数据失败');
            }
        },

        async saveFileToDataFolder(content) {
            // 通过API保存文件到@data/文件夹
            const filename = `OHIP-14评估结果_${this.recorderInfo.surveyId}_${this.formData.patientName}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`;

            const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-file`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    filename: filename,
                    content: content,
                    surveyId: this.recorderInfo.surveyId
                })
            });

            if (!response.ok) {
                throw new Error('保存评估报告失败');
            }
        },

        resetForm() {
            this.formData = {};
            this.result = {
                totalScore: 0,
                maxScore: 56,
                diagnosis: '',
                explanation: '',
                details: {}
            };
            this.showResult = false;
            this.initializeForm();
        }
    }
}
</script>

<style scoped>
.ohip14-survey {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
    margin: 0 0 10px 0;
    font-size: 2.5em;
    font-weight: 300;
}

.subtitle {
    margin: 0 0 20px 0;
    font-size: 1.2em;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.home-btn,
.settings-btn {
    padding: 10px 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.home-btn:hover,
.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

/* 设置模态框样式 */
.settings-modal,
.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.settings-content,
.export-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.settings-header,
.export-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 5px;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: #f0f0f0;
    color: #333;
}

/* 记录人信息显示 */
.recorder-info-display {
    margin-bottom: 30px;
}

.recorder-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #667eea;
}

.recorder-main-info h3 {
    margin: 0 0 5px 0;
    color: #333;
}

.recorder-main-info p {
    margin: 5px 0;
    color: #666;
}

.recorder-actions {
    display: flex;
    gap: 10px;
}

.edit-recorder-btn,
.export-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.edit-recorder-btn:hover {
    background: #f0f0f0;
}

.export-btn {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.export-btn:hover {
    background: #218838;
}

/* 表单样式 */
.section {
    background: white;
    padding: 30px;
    margin-bottom: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.section h2 {
    color: #333;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

.section-description {
    color: #666;
    line-height: 1.6;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 5px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.required {
    color: #dc3545;
    margin-left: 3px;
}

.form-input,
.form-textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* 单选按钮组 */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 10px;
}

.radio-option {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px 15px;
    border: 2px solid #ddd;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.radio-option:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.radio-option input[type="radio"] {
    margin-right: 8px;
    cursor: pointer;
}

.radio-option input[type="radio"]:checked+.radio-label {
    color: #667eea;
    font-weight: 500;
}

.radio-option:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: #e8ebff;
}

.radio-label {
    user-select: none;
}

/* 问题组 */
.question-group {
    margin-top: 30px;
}

.question-group h3 {
    color: #333;
    margin-bottom: 10px;
}

.group-description {
    color: #666;
    margin-bottom: 20px;
    font-style: italic;
}

.question-item {
    margin-bottom: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.question-header {
    margin-bottom: 15px;
}

.question-label {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    line-height: 1.5;
}

/* 表单导航 */
.form-navigation {
    display: flex;
    justify-content: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #f0f0f0;
}

.submit-btn {
    padding: 15px 40px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.submit-btn:hover:not(:disabled) {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.submit-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 结果展示 */
.result-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.result-section h2 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
}

.result-card {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 10px;
}

.result-summary {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #ddd;
}

.result-summary h3 {
    color: #667eea;
    font-size: 1.8em;
    margin-bottom: 15px;
}

.score {
    font-size: 1.5em;
    font-weight: 600;
    color: #333;
}

.result-details {
    margin-bottom: 30px;
}

.result-details h4 {
    color: #333;
    margin-bottom: 15px;
}

.question-scores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.question-score-item {
    padding: 15px;
    background: white;
    border-radius: 5px;
    border-left: 3px solid #667eea;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.question-id {
    font-weight: 600;
    color: #667eea;
}

.question-label {
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

.question-score {
    font-weight: 500;
    color: #333;
}

.result-explanation {
    padding: 20px;
    background: white;
    border-radius: 5px;
    border-left: 4px solid #28a745;
}

.result-explanation h4 {
    color: #333;
    margin-bottom: 10px;
}

.result-explanation p {
    color: #666;
    line-height: 1.6;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 30px;
}

.save-btn,
.reset-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-btn {
    background: #28a745;
    color: white;
}

.save-btn:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

.save-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.reset-btn {
    background: #6c757d;
    color: white;
}

.reset-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.field-hint {
    font-size: 12px;
    color: #999;
    margin-top: 5px;
}

.settings-actions,
.export-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
}

.save-settings-btn,
.export-confirm-btn {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-settings-btn:hover,
.export-confirm-btn:hover:not(:disabled) {
    background: #5568d3;
}

.export-confirm-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.cancel-btn {
    padding: 10px 20px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-btn:hover {
    background: #5a6268;
}

.export-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 20px;
}

.export-info p {
    margin: 5px 0;
    color: #666;
}

.export-options {
    margin-bottom: 20px;
}

.export-options .form-group {
    margin-bottom: 10px;
}

.export-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ohip14-survey {
        padding: 10px;
    }

    .header h1 {
        font-size: 2em;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .radio-group {
        flex-direction: column;
    }

    .question-scores-grid {
        grid-template-columns: 1fr;
    }
}
</style>
